import { EyeOutlined } from "@ant-design/icons";
import { Button, Space, Tag } from "antd";
import dayjs from "dayjs";

export function tableColumns(viewLogDetail: any) {
    return [
        {
          title: 'ID',
          dataIndex: 'id',
          key: 'id',
          width: 80,
        },
        {
          title: '用户名',
          dataIndex: 'user_name',
          key: 'user_name',
          width: 100,
        },
        {
          title: '操作模块',
          dataIndex: 'module',
          key: 'module',
          width: 120,
        },
    
        {
          title: '操作名称',
          dataIndex: 'operation_name',
          key: 'operation_name',
          width: 150,
        },
        {
          title: '请求方法',
          dataIndex: 'request_method',
          key: 'request_method',
          width: 100,
          render: (text: string) => {
            const color = text === 'GET' ? 'blue' : text === 'POST' ? 'green' : text === 'PUT' ? 'orange' : text === 'DELETE' ? 'red' : 'default';
            return <Tag color={color}>{text}</Tag>;
          },
        },
        {
          title: 'IP地址',
          dataIndex: 'operation_ip',
          key: 'operation_ip',
          width: 120,
        },
        {
          title: '状态',
          dataIndex: 'status',
          key: 'status',
          width: 80,
          render: (status: number) => (
            <Tag color={status === 0 ? 'success' : 'error'}>
              {status === 0 ? '成功' : '失败'}
            </Tag>
          ),
        },
        {
          title: '耗时(ms)',
          dataIndex: 'cost_time',
          key: 'cost_time',
          width: 100,
          render: (time: number) => (
            <span style={{ color: time > 1000 ? 'red' : time > 500 ? 'orange' : 'green' }}>
              {time}
            </span>
          ),
        },
        {
          title: '操作时间',
          dataIndex: 'operation_time',
          key: 'operation_time',
          width: 180,
          render: (time: string) => dayjs(time).format('YYYY-MM-DD HH:mm:ss'),
        },
        {
          title: '操作',
          key: 'action',
          width: 100,
          fixed: 'right',
          render: (_: any, record: any) => (
            <Space size="middle">
              <Button
                type="link"
                icon={<EyeOutlined />}
                onClick={() => viewLogDetail(record)}
              >
                详情
              </Button>
            </Space>
          ),
        },
      ];
}